<%--
  Created by IntelliJ IDEA.
  User: carol
  Date: 2018/6/12
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*,javax.servlet.*,functest.*" pageEncoding="utf-8" %>
<%@ page import="java.sql.SQLException" %>
<html>
<head>
    <title>航班信息管理</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="js/jquery-3-2-1.js"></script>
    <link type="text/css" rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="layui/layui.all.js"></script>
    <link type="text/css" rel="stylesheet" href="css/style.css" media="all">
</head>
<body>
<div class="head" >
    <div class="head-text">
        <li class="title">航空票务系统</li>
    </div>
    <a href="index.jsp"><img class="logo" src="img/logo.png" ></a>
</div>
<div style="margin-top: 100px;">
<ul class="layui-nav layui-nav-tree layui-nav-side" style="top: 60;">
    <li class="layui-nav-item">
        <a href="mgrcity.jsp">城市机场管理</a>
    </li>
    <li class="layui-nav-item">
        <a href="mgrtk.jsp">票务信息管理</a>
    </li>
    <li class="layui-nav-item layui-nav-itemed"><a href="mgrflight.jsp">航班管理</a></li>
</ul>
<div style="margin-left: 220px;margin-right: 20px">
    <blockquote class="layui-elem-quote">航班信息</blockquote>
    <table lay-filter="hbtable" >
        <thead>
        <tr>
            <th lay-data="{field:'hbid',align:'center',sort: true}">航班名称</th>
            <th lay-data="{field:'planeid',align:'center',sort: true}">飞机机型</th>
            <th lay-data="{field:'weekplan',align:'center',sort: true}">起飞日程</th>
            <th lay-data="{field:'topseat',align:'center',sort: true}">头等舱数</th>
            <th lay-data="{field:'ecoseat',align:'center',sort: true}">经济舱数</th>
            <th lay-data="{fixed: 'right', minWidth: 220, align:'center', toolbar: '#barspxx'}">操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            FindAPrint func =new FindAPrint();
            try {
                List<Map<String,String>> hb=func.Findallhb();
                for(Map<String,String> hbmap:hb) {
                    out.println("<tr><td>"+ hbmap.get("hbid") +"</td><td>"
                            + hbmap.get("planeid") +"</td><td>"
                            + hbmap.get("weekplan") +"</td><td>"
                            + hbmap.get("topseat") +"</td><td>"
                            + hbmap.get("ecoseat") +"</td><td>");
                    out.println("</td><td></td></tr>");
                }
            }catch (Exception e){
                out.println(e);
            }
        %>
        </tbody>
    </table>
    <div style="text-align: center">
        <button class="layui-btn layui-btn-primary" id="addhb">添加航班</button>
        <a href="index.jsp" class="layui-btn layui-btn-normal">返回</a>
    </div>
</div>
</div>

</body>
</html>

<script type="text/html" id="barspxx">
    <a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-xs" lay-event="edithb">航班编辑</a>
    <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="edithd">航线查看</a>
    <a class="layui-btn layui-btn-radius layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    layui.use(['jquery','layer','table'], function(){
        var layer = layui.layer
            ,element = layui.element
            ,$= layui.$
            ,table=layui.table;

        //转换静态表格
        table.init('hbtable', {limit: 10,page:true});
        //监听工具条
        table.on('tool(hbtable)', function(obj){
            var data = obj.data;
            var hb_id = data['hbid'];
            var planeid = data['planeid'];
            var topseat = data['topseat'];
            var ecoseat = data['ecoseat'];
            var delurl = 'changehb.jsp?action=del&hbid=' + hb_id;
            var edithburl = 'edithb.jsp?hbname=' + hb_id + "&plane=" + planeid +  "&topseat=" + topseat + "&ecoseat=" + ecoseat;
            var edithdurl = 'edithd.jsp?hbname=' + hb_id;
            if(obj.event === 'edithb'){
                layer.open({
                    type: 2,
                    title: "编辑航班",
                    content: edithburl,
                    area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 26 / 30 + "px"],
                });
            }
            else if(obj.event === 'edithd'){
                layer.open({
                    type: 2,
                    title: "编辑航段 ",
                    content: edithdurl,
                    area: [window.innerWidth * 26 / 30 + "px", window.innerHeight * 26 / 30 + "px"],
                });
            }
            else if(obj.event === 'del'){
                layer.open({
                    type: 2,
                    title: "删除航班",
                    content: delurl,
                    area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 10 / 30 + "px"],
                });
            }
        });
        $("#addhb").click(function (){
            var addhburl = "changehb.jsp?action=add";
            layer.open({
                type: 2,
                title: "添加航班",
                content: addhburl,
                area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 26 / 30 + "px"],
            });
        });
    });
</script>
